package cn.zjj.feignClient.fallbackFactory;

import cn.zjj.domain.Store;
import cn.zjj.feignClient.StoreFeignClient;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class StoreFallbackFactory implements FallbackFactory<StoreFeignClient> {
    @Override
    public StoreFeignClient create(Throwable throwable) {
        return new StoreFeignClient() {
            @Override
            public Map<String, Object> add(Store store) {
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("success", false);
                hashMap.put("message", "熔断异常");
                hashMap.put("state", 500);
                return hashMap;
            }

            @Override
            public Map<String, Object> update(Store store) {
                HashMap<String, Object> hashMap = new HashMap<>();
                hashMap.put("success", false);
                hashMap.put("message", "熔断异常");
                hashMap.put("state", 500);
                return hashMap;
            }

            @Override
            public Store selectById(Long productId) {
                return new Store(-1L,-1L,500);
            }

        };
    }
}
